package com.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 验证正则表达式小工具
 * 
 * @author Administrator
 * 
 */
public class Tools {
	// abcabcabcdefabc abc+ (abc)+ (abc){2,}
	public static void main(String[] args) {
		if (args.length < 2) {
			System.exit(0);
		}

		System.out.println("Input:\"" + args[0] + "\"");

		for (String arg : args) {
			System.out.println("Regular expression: \"" + arg + "\"");
			Pattern p = Pattern.compile(arg);
			Matcher m = p.matcher(args[0]);
			while (m.find()) {
				System.out.println("Match \"" + m.group() + "\" at positions "
						+ m.start() + "-" + (m.end() - 1));
			}
		}
	}

}
